#include "qdatabasemanager.h"

#include "qconfigdatabase.h"
#include "qhistorydatabase.h"
#include "qlogdatabase.h"

QDataBaseManager::QDataBaseManager(QObject *parent) :
    QObject(parent),
    m_config_database(new QConfigDataBase),
    m_history_database(new QHistoryDataBase),
    m_log_database(new QLogDatabase)
{
}

QDataBaseManager::~QDataBaseManager()
{
    delete m_config_database;
    delete m_history_database;
    delete m_log_database;
}

void QDataBaseManager::load(const QString &project_path)
{
    m_config_database->open(project_path);
    m_history_database->open(project_path);
    m_log_database->open(project_path);
}

QMap<QString,QString> QDataBaseManager::get_hold_data()
{
    return m_config_database->get_hold_data();
}

void QDataBaseManager::set_hold_data(const QString &uuid, const QVariant &value)
{
    m_config_database->save_hold_data(uuid,value);
}

void QDataBaseManager::save_data(tagDataInfo *info, const QString &time)
{
    m_history_database->save_data(info,time);
}

void QDataBaseManager::set_project_property(const QString &key, const QString &value)
{
    m_history_database->set_property(key,value);
    m_log_database->set_property(key,value);
}

void QDataBaseManager::add_log(const QString &time, const QString &user, const QString &tag, const QString &msg)
{
    m_log_database->add_log(QStringList()<<time<<user<<tag<<msg);
}
